<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      window.onload = function () {
        // var str = "    andy        ";
        var str2 = new String("    andy        ");
        console.log(str);
        var str1 = str.trim();
        console.log(str1);
        var input = document.querySelector("input");
        var btn = document.querySelector("button");
        var div = document.querySelector("div");
        btn.onclick = function () {
          var str = input.value.trim();
          if (str === "") {
            alert("请输入内容");
          } else {
            console.log(str);
            console.log(str.length);
            div.innerHTML = str;
          }
        };
      };
    </script>
  </head>
  <body>
    <input type="text" /><button>点击</button>
    <div></div>
  </body>
</html>
